<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Analyzer Test</title></head>
<body>
<h1>Crunchy analyzer Test</h1>

<p>Analyzers are tools which can analyze the quality of code, make reports
about when something bad is found, and score the quality of the code.</p>

<p>Those tools are not a part of Crunchy, you must install them on your
computer. Currently, there are three supported analyzers:</p>
<ul>
<li><a href="http://www.logilab.org/857" title="external_link">Pylint</a></li>
<li><a href="http://pychecker.sourceforge.net/" title="external_link">PyChecker</a></li>
<li><a href="http://divmod.org/trac/wiki/DivmodPyflakes" title="external_link">PyFlakes</a></li>
</ul>

<h2>Configuration</h2>

<p>You can choose your analyzer (or disable analysis) using the option:</p>
<pre title="interpreter">
crunchy.analyzer = None         # Disable analysis
crunchy.analyzer = 'pylint'     # Use Pylint
crunchy.analyzer = 'pychecker'  # Use PyChecker
crunchy.analyzer = 'pyflakes'   # Use PyFlakes
</pre>

<h2>Making analysis</h2>

<p>Please notice that the report and the score displayed heavy depend on
what analyzer you use. Pylint is far more sever than PyChecker.</p>

<p>The analyzer plugin add several <acronym title="Very Little Additional
Markup">VLAM</acronym> options:</p>

<ul>
<li><code>analyzer</code>: a new widget to make analysis</li>
<li><code>analyzer_score</code>: for editors, doctest and unittest, display
the score after the normal execution</li>
<li><code>analyzer_report</code>: for editors, doctest and unittest, add a
button to analyze the code</li>
</ul>

<h3>The analyzer widget</h3>

<p>The analyzer widget is an editor with a button to make a report and a score
about the code.</p>

<p>Here is some code that will raise warnings with Pylint (PyChecker fails to
analyze it):</p>

<pre title="analyzer">
def Function_without_DocString(msg):
    print msg

foo=missingvar
Function_without_DocString(missingvar)
</pre>

<p>Here is another bad code, to try with PyChecker:</p>
<pre title="analyzer">
# Unused import
import this
# Statement with no effect
True
# Nice, well known and useful piece of code
print "Hello world"
</pre>

<h3>With the editor</h3>

<p>Here is an editor with the <code>analyzer_score</code> option (<em>this
doesn't add another button, but let the existing one display the score reported
by the analyzer</em>):</p>
<pre title="editor analyzer_score">
def Function_without_DocString(msg = []):
    this_variable_is_not_used = 42
    print ' '.join(msg)

Function_without_DocString(['Hello', 'world'])
</pre>

<h3>With doctest</h3>

<p>Here is a doctest editor with the <code>analyzer_report</code> option:</p>
<pre title="doctest analyzer_report">
This force your function to have a bad name:
    >>> Function_with_A_BadName(['A', 'message'])
    A message
</pre>

<p>You can try this code:</p>
<pre title="py_code">
def Function_with_A_BadName(msg = []):
    this_variable_is_not_used = 42
    print ' '.join(msg)
</pre>

<h3>With unittest</h3>

<p>And here a unittest editor with both <code>analyze_report</code> and
<code>analyzer_score</code>:</p>

<pre title="unittest analyzer_report analyzer_score">
class BadCodeTest(unittest.TestCase):
    """Test class for the bad_named_class class"""
    def test_bad_named_class(self):
        """Tests for the initialization of bad_named_class"""
        bad_object = bad_named_class()
        self.assertEquals(bad_object.BadAttribName, 42)
</pre>

<p>You can try this code:</p>
<pre title="py_code">
class bad_named_class(object):
    BadAttribName = 42
</pre>

<h2>Bugs</h2>

<p>Please notice that the score displayed while using PyChecker is made by
Crunchy from the PyChecker report, because PyChecker itself doesn't make
scores.</p>

<ul>
  <li>No bug known.</li>
</ul>

<p><a href="index.html">Back to the test index</a></p>
</body>
</html>
